package com.innovation.chengzhangriji.http;

import android.util.Log;

import com.innovation.chengzhangriji.ui.event.BaseEvent;
import com.innovation.library.http.InnovationHttpResponseHandler;

import de.greenrobot.event.EventBus;

public class ResponseHandler extends InnovationHttpResponseHandler {

    // 请求缺少必须参数
    private static final String FAILURE_2001 = "2001";

    // Sc或Sc未授权
    private static final String FAILURE_2002 = "2002";

    // 手机号被占用
    private static final String FAILURE_2003 = "2003";

    // 错误的手机号格式
    private static final String FAILURE_2004 = "2004";

    // 发送短信失败
    private static final String FAILURE_2005 = "2005";

    // 错误的手机注册验证码
    private static final String FAILURE_2006 = "2006";

    // 用户不存在或者密码错误
    private static final String FAILURE_2007 = "2007";

    // 手机号未被注册
    private static final String FAILURE_2008 = "2008";

    // 错误的重置密码验证码
    private static final String FAILURE_2009 = "2009";

    // 访问令牌错误
    private static final String FAILURE_2010_1 = "2010.1";

    // 访问令牌过期
    private static final String FAILURE_2010_2 = "2010.2";

    // 刷新令牌错误
    private static final String FAILURE_2010_3 = "2010.3";

    // 未注册的手机号或登录动态码错误
    private static final String FAILURE_2011 = "2011";

    // 与宝贝未建立关联
    private static final String FAILURE_2012 = "2012";

    // 重复的称谓（一个宝宝不能对应完全相同称谓的多个用户,例：不能有两个叫“妈妈”的称谓）
    private static final String FAILURE_2013 = "2013";

    // 二维码过期
    private static final String FAILURE_2014_1 = "2014.1";

    // 二维码无效
    private static final String FAILURE_2014_2 = "2014.2";

    // 没有可更新的数据
    private static final String FAILURE_2015 = "2015";

    // 与宝贝重复建立关联
    private static final String FAILURE_2016 = "2016";

    // 本地操作时间戳早于云端操作时间戳,操作未被执行
    private static final String FAILURE_2017 = "2017";

    // 日记ID不存在
    private static final String FAILURE_2018 = "2018";

    // 有新数据未获取
    private static final String FAILURE_2019 = "2019";

    // 注册失败
    private static final String FAILURE_2020 = "2020";

    // ID已经存在,不能重复添加
    private static final String FAILURE_2021 = "2021";

    // 非法的票据
    private static final String FAILURE_2022_1 = "2022.1";

    // 非法的块号
    private static final String FAILURE_2022_2 = "2022.2";

    // 上传失败,请重传
    private static final String FAILURE_2022_3 = "2022.3";

    // 不能重复申请
    private static final String FAILURE_2023 = "2023";

    // 其他用户已经处理过申请
    private static final String FAILURE_2024 = "2024";

    // 没有权限执行当前操作
    private static final String FAILURE_2025 = "2025";

    // 超管不能取消关联
    private static final String FAILURE_2026 = "2026";

    // 其他用户已经处理过邀请
    private static final String FAILURE_2027 = "2027";

    // 角色不符，不能调用此接口
    private static final String FAILURE_2028 = "2028";

    // 状态错误
    private static final String FAILURE_2029 = "2029";

    // 角色设置错误
    private static final String FAILURE_2030_1 = "2030.1";

    // 权限设置错误
    private static final String FAILURE_2030_2 = "2030.2";

    // 查看范围设置错误
    private static final String FAILURE_2030_3 = "2030.3";

    // 该受邀人已被邀请
    private static final String FAILURE_2031 = "2031";

    // 当前用户已经在申请中
    private static final String FAILURE_2036 = "2036";

    // 当前用户已经在邀请中
    private static final String FAILURE_2037 = "2037";

    @Override
    public void onInnovationFailure(String msg) {
        if (msg.equals(FAILURE_2001)) {
            onChZhRJFailure("请求缺少必须参数");
        } else if (msg.equals(FAILURE_2002)) {
            onChZhRJFailure("Sc或Sc未授权");
        } else if (msg.equals(FAILURE_2003)) {
            onChZhRJFailure("手机号被占用");
        } else if (msg.equals(FAILURE_2004)) {
            onChZhRJFailure("错误的手机号格式");
        } else if (msg.equals(FAILURE_2005)) {
            onChZhRJFailure("发送短信失败");
        } else if (msg.equals(FAILURE_2006)) {
            onChZhRJFailure("错误的手机注册验证码");
        } else if (msg.equals(FAILURE_2007)) {
            onChZhRJFailure("用户不存在或者密码错误");
        } else if (msg.equals(FAILURE_2008)) {
            onChZhRJFailure("手机号未被注册");
        } else if (msg.equals(FAILURE_2009)) {
            onChZhRJFailure("错误的重置密码验证码");
        } else if (msg.equals(FAILURE_2010_1)) {
            onChZhRJTokenFailure("访问令牌错误");
        } else if (msg.equals(FAILURE_2010_2)) {
            onChZhRJTokenFailure("访问令牌过期");
        } else if (msg.equals(FAILURE_2010_3)) {
            onChZhRJTokenFailure("刷新令牌错误");
        } else if (msg.equals(FAILURE_2011)) {
            onChZhRJFailure("未注册的手机号或登录动态码错误");
        } else if (msg.equals(FAILURE_2012)) {
            onChZhRJFailure("与宝贝未建立关联");
        } else if (msg.equals(FAILURE_2013)) {
            onChZhRJFailure("该称谓已关注!");
        } else if (msg.equals(FAILURE_2014_1)) {
            onChZhRJFailure("二维码过期");
        } else if (msg.equals(FAILURE_2014_2)) {
            onChZhRJFailure("二维码无效");
        } else if (msg.equals(FAILURE_2015)) {
            onChZhRJFailure("没有可更新的数据");
        } else if (msg.equals(FAILURE_2016)) {
            onChZhRJFailure("已关注了该宝贝,无需再次添加哦~!");
        } else if (msg.equals(FAILURE_2017)) {
            onChZhRJFailure("本地操作时间戳早于云端操作时间戳,操作未被执行");
        } else if (msg.equals(FAILURE_2018)) {
            onChZhRJFailure("日记ID不存在");
        } else if (msg.equals(FAILURE_2019)) {
            onChZhRJFailure("有新数据未获取");
        } else if (msg.equals(FAILURE_2020)) {
            onChZhRJFailure("注册失败");
        } else if (msg.equals(FAILURE_2021)) {
            onChZhRJFailure("该手机号用户已经关注!");
        } else if (msg.equals(FAILURE_2022_1)) {
            onChZhRJFailure("非法的票据");
        } else if (msg.equals(FAILURE_2022_2)) {
            onChZhRJFailure("非法的块号");
        } else if (msg.equals(FAILURE_2022_3)) {
            onChZhRJFailure("上传失败,请重传");
        } else if (msg.equals(FAILURE_2023)) {
            onChZhRJFailure("不能重复申请");
        } else if (msg.equals(FAILURE_2024)) {
            onChZhRJFailure("其他用户已经处理过申请");
        } else if (msg.equals(FAILURE_2025)) {
            onChZhRJFailure("没有权限执行当前操作");
        } else if (msg.equals(FAILURE_2026)) {
            onChZhRJFailure("您是大家长,请先转移权限!");
        } else if (msg.equals(FAILURE_2027)) {
            onChZhRJFailure("其他用户已经处理过邀请");
        } else if (msg.equals(FAILURE_2028)) {
            onChZhRJFailure("角色不符,不能调用此接口");
        } else if (msg.equals(FAILURE_2029)) {
            onChZhRJFailure("状态错误");
        } else if (msg.equals(FAILURE_2030_1)) {
            onChZhRJFailure("角色设置错误");
        } else if (msg.equals(FAILURE_2030_2)) {
            onChZhRJFailure("权限设置错误");
        } else if (msg.equals(FAILURE_2030_3)) {
            onChZhRJFailure("查看范围设置错误");
        } else if (msg.equals(FAILURE_2031)) {
            onChZhRJFailure("该受邀人已被邀请");
        } else if (msg.equals(FAILURE_2036)) {
            onChZhRJFailure("该用户申请中,暂不可操作");
        } else if (msg.equals(FAILURE_2037)) {
            onChZhRJFailure("该用户受邀中,暂不可操作");
        }
    }

    @Override
    public void onInnovationError() {
        onChZhRJFailure("服务器内部错误");
    }

    @Override
    public void onInnovationExceptionFinish() {
        onChZhRJFailure("网络连接超时");
    }

    /**
     * 普通请求失败
     *
     * @param value 失败信息
     */
    public void onChZhRJFailure(String value) {
        Log.d("onChZhRJFailure", value);
    }

    /**
     * 令牌相关请求失败
     *
     * @param value 失败信息
     */
    public void onChZhRJTokenFailure(String value) {
        Log.d("onChZhRJTokenFailure", value);

        // 访问Token错误
        BaseEvent event = new BaseEvent();
        event.setType(BaseEvent.TYPE_LOG_STATE_CHANGED);
        EventBus.getDefault().post(event);
    }
}
